package com.eudon.design_pattern.behavioral.observer.event_bus;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author eudon
 * @description 用户注册控制器(被观察者)
 * @date 2025/9/2
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class UserController {
    private final EventBus eventBus;

    public UserController(List<Object> observers) throws InvocationTargetException, IllegalAccessException {
        this.eventBus = new EventBus();
        for (Object observer : observers) {
            eventBus.subscribe(observer);
        }
    }

    public void createUser() throws InvocationTargetException, IllegalAccessException {
        //1.注册用户
        System.out.println("创建用户成功");
        //2.通过观察者给用户发送体验金
        //模拟创建用户之后的用户ID是1
        eventBus.post(1L);
    }
}
